package cn.qiyu5522.config;

import cn.qiyu5522.interceptors.RequestIdInterceptor;
import cn.qiyu5522.interceptors.TraceIdRequestLoggingInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * ClassName: WebConfig
 * Package: cn.qiyu5522.config
 * Description:
 *
 * @Author: Tonkey
 * @Create：2024/4/9-20:34
 * @Version: v1.0
 */

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    private RequestIdInterceptor requestIdInterceptor;

    @Autowired
    private TraceIdRequestLoggingInterceptor traceIdRequestLoggingInterceptor;

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                // 设置允许跨域请求的域名
                .allowedOriginPatterns("*")
                // 是否允许cookie
                .allowCredentials(true)
                // 设置允许的请求方式
                .allowedMethods("GET", "POST", "DELETE", "PUT")
                // 设置允许的header 属性
                .allowedHeaders("*")
                // 跨域允许时间
                .maxAge(3600);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
     /*   registry.addInterceptor(traceIdRequestLoggingInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/swagger-resources/**", "/webjars/**", "/v2/**", "/swagger-ui.html/**"); // 放行Swagger
    */
    }

}
